package com.qianyu.api.controller.back.usermag;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianyu.core.entity.base.BaseIdDto;
import com.qianyu.core.entity.base.Result;
import com.qianyu.core.entity.bean.User;
import com.qianyu.core.entity.dto.UserDTO;
import com.qianyu.core.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "后台管理-用户管理", description = "wangzhicheng")
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class AdminController {
    private final UserService userService;



    /**
     * 添加代理
     */
    @PostMapping("/registerUser")
    @ApiOperation(value = "添加代理")
    Result<String> registerUser(@Validated @RequestBody UserDTO.UserSaveDTO dto) {
        userService.registerUser(dto);
        return Result.success();
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/changeUserInfo")
    @ApiOperation(value = "修改用户信息")
    Result<String> changeUserInfo(@Validated @RequestBody UserDTO.UserUpdateDto dto) {
        userService.changeUserInfo(dto);
        return Result.success();
    }

    /**
     * 根据用户id查询用户信息
     */
    @PostMapping("/getInfo")
    @ApiOperation(value = "根据用户id查询用户信息")
    Result<User> getInfo(@Validated @RequestBody BaseIdDto dtO) {
        return Result.success(userService.getInfo(dtO));
    }

    /**
     * 查询用户列表
     */
    @PostMapping("/pageListUser")
    @ApiOperation(value = "查询用户列表")
    Result<Page<User>> pageListUser(@Validated @RequestBody UserDTO.UserPageDTO dto) {
        return Result.success(userService.pageListUser(dto));
    }

    /**
     * 修改用户密码
     */
    @PostMapping("/changePassword")
    @ApiOperation(value = "修改用户密码")
    Result<String> changePassword(@Validated @RequestBody UserDTO.PasswordDto dto) {
        userService.changePassword(dto);
        return Result.success();
    }
}
